﻿<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<title>软件详细信息</title>
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1" />

<link href="${mvcPath}/dacp-view/aijs/css/ai.css" type="text/css" rel="stylesheet" />
<style>
.media, .media-body {
	overflow: inherit;
	zoom: 1;
}

.list-group-item.active .dropdown-menu a {
	color: black;
}

small {
	font-size: 9px;
}
.fuelux .wizard {
	border-right: 0px;
	border-bottom: 1px solid #eee;
	box-shadow: 0 0px 0px;
	background-color: transparent;
	box-shadow: none;
	border-radius: 0px;
}

.wrapper {
	padding: 1px 15px 15px 15px;
}

.panel-body {
	padding: 2px 0px 5px 0px;
}
</style>
<script type="text/javascript"
	src="${mvcPath}/dacp-lib/jquery/jquery-1.10.2.min.js"></script>
<script type="text/javascript"
	src="${mvcPath}/dacp-lib/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-lib/underscore/underscore-min.js"></script>	
<script src="${mvcPath}/dacp-lib/cryptojs/aes.js" type="text/javascript"></script>
<script src="${mvcPath}/crypto/crypto-context.js" type="text/javascript"></script>
<script src="${mvcPath}/dacp-view/aijs/js/ai.core.js"></script>
<script src="${mvcPath}/dacp-view/aijs/js/ai.field.js"></script>
<script src="${mvcPath}/dacp-view/aijs/js/ai.jsonstore.js"></script>
<script src="${mvcPath}/dacp-view/aijs/js/ai.grid.js"></script>

<script src="${mvcPath}/dacp-view/aijs/js/ai.treeview.js"> </script>
<script src="${mvcPath}/dacp-res/catalog/common/js/ai.meta.widget.js"></script>
<script src="${mvcPath}/dacp-res/catalog/software/js/ai.meta.soft.js"></script>
 
 

 
<style>
.media, .media-body {
	overflow: inherit;
	zoom: 1;
}

.list-group-item.active .dropdown-menu a {
	color: black;
}

small {
	font-size: 9px;
}

 

.wrapper {
	padding: 1px 15px 15px 15px;
}
  

a.task {
	font-size: 13px;
}

.toolbar {
	margin-top: 10px;
	margin-bottom: 10px;
}

.toolbar .form-control {
	display: inline;
	padding: 1px 2px;
}

.toolbar button {
	margin-left: 10px;
}
.panel .table-striped > thead th {
    background-color: #36B0C8;
}
td input{
	width:100%;
}
.form-horizontal .form-group {
    margin-left: 0px;
    margin-right: 0px;
}
</style>
<script>
var METAPRJ = paramMap.METAPRJ || "";
var _METAPRJ = METAPRJ ? '_' + METAPRJ : '';
var metadbStore = ai.getJsonStore("select driverclassname,username from metadbcfg where dbname='METADB'");
var dbDriverClass =metadbStore.getAt(0).get('DRIVERCLASSNAME');
var username = metadbStore.getAt(0).get('USERNAME');
var selectTabSql = '';
if(dbDriverClass.indexOf('oracle')!=-1){
	selectTabSql ="select t.table_name as values1, q.comments as values2,t.tablespace_name as values3 from user_tables t, user_tab_comments q where t.table_name = q.table_name";
}else if(dbDriverClass.indexOf('mysql')!=-1){
	selectTabSql ="SELECT table_name as values1,table_comment as values2 FROM information_schema.tables WHERE WHERE UPPER(TABLE_SCHEMA)='"+username.toUpperCase()+"'";
}
 $(document).ready(function() {  
 	 ai.loadWidget("sheetgrid");
 	var objtype="SOFT";
 	var objcode=paramMap.objname||'DAG-METAFRAME';
 	var objtabname="";
 	var softItemStore={};
 	
 	var metasoft=new AI.Meta(objtype);
 	$('#select-table').on('click',function(e){
 		function afterTabSelect(rs){
 			for(var i=0;i<rs.length;i++){
 				var r=softItemStore.getNewRecord();
 				r.set('ACTCODE',rs[i].get('VALUES1'));
 				r.set('ACTNAME',rs[i].get('VALUES2'));
 				r.set('ACTTYPE','TAB');
 				r.set('PARENTCODE','TAB');
 				r.set('PROVIDER',objcode);
 				softItemStore.add(r);
 			}
 			softItemStore.commit();
 			softItemStore.select();
 		};
	 	var selBox=new SelectBox({sql:selectTabSql,backdrop:'static',callback:afterTabSelect});
     	selBox.show();
        $('#selectgrid_page li a.pre').css('display','none');
        $('#selectgrid_page li a.next').css('display','none');
	});
	 $('#select-model').on('click',function(e){
 		function afterTabSelect(rs){
 			for(var i=0;i<rs.length;i++){
 				var r=softItemStore.getNewRecord();
 				r.set('ACTCODE',rs[i].get('VALUES1'));
 				r.set('ACTNAME',rs[i].get('VALUES2'));
 				r.set('PARENTCODE','MODEL');
 				r.set('ACTTYPE','MODEL');
 				r.set('ORDSEQ',rs[i].get('SEQ'));
 				r.set('URL',rs[i].get('URL'));
 				r.set('ICONCLASS',rs[i].get('IMAGES'));
 				r.set('PROVIDER',objcode);
 				softItemStore.add(r);
 			}
 			softItemStore.commit();
 			softItemStore.select();
 		};
 		var selSql="select modelcode as values1, modelname as values2,remark as values3,seq,url,images from metamodel"; 
	 	var selBox=new SelectBox({sql:selSql,backdrop:'static',callback:afterTabSelect});
     	selBox.show();
        $('#selectgrid_page li a.pre').css('display','none');
        $('#selectgrid_page li a.next').css('display','none');
	});
 	function buildObjBaseInfo(){
 		var objAttrStore=ai.getStoreData("select * from metaobjcfg where objtype='"+objtype+"' order by seq");
 		var objDataStore=ai.getStoreData("select * from metasoftcfg where SOFTSYSCODE='"+objcode+"'");
 		var html = '<fieldset> <table class="table"> <tbody>';
 		var objdbRec=objDataStore[0];
 		for(var i=0;i<objAttrStore.length;i++){
 			var objAttrItem = objAttrStore[i];
 			var value=objdbRec[objAttrItem.ATTRNAME];
			if(value==null||value=='undefined'){
				value='未知';
			}
			if(value.length>25){
				value=value.substring(0,25)+"...";
			}
			html+='<tr> <th class="strong w-80px"> '+objAttrItem.ATTRCNNAME+'</th><td>'+value+' </td></tr>';
 			//html+='<tr > <th class="strong w-80px"> '+objAttrItem.ATTRCNNAME+'</th><td>'+objdbRec[objAttrItem.ATTRNAME]||""+' </td></tr>';
 		};
         html+='</tbody></table></fieldset>';              
         $("#objbaseinfo").empty().append(html);                 
                            
                        
 	};
 	/*软件的功能列表*/
  function buildSoftExtendInfo(caneditable){
	  
		 //var sql="SELECT XMLID, PRO_KEY, PRO_VALUE, PARENTCODE, PRO_NAME, REMARK,ITEMCODE FROM metaobj_property where xmlid='"+objcode+"'";
		var sql="select modelcode,parentcode,modelname,remark,seq,url,frame,images,state from metamodel where modelcode like '%"+objcode+"%'" ;
	  softExtendstore=  new AI.JsonStore({
                sql:sql,
                key:"MODELCODE",
                pageSize:-1,
                table:"metamodel"  
      });
     
//   		if(softExtendstore.getCount()==0){
//   			var sql="insert into  metaobj_property(XMLID, pro_key, pro_value, parentcode, pro_name, remark, itemcode) select '"+objcode+"',PARACODE,PARATEXT,PARENTCODE,PARANAME,REMARK,itemcode from metaobjmodel_def where OBJTYPE='"+objtype+"' and REFNAME<>'private' order by itemcode";
//   			ai.executeSQL(sql);
//   			softExtendstore.select();
//   		};
		var config = {
			id : "softextendInfo",
			width : "100%",
			renderTo : "softextendInfo",
			headerAlign : "left",
			headerHeight : "30",
			dataAlign : "left",
			indentation : "20",
			hoverRowBackground : "true",
			folderColumnIndex : "0",
			itemClick : itemClickEvent,
			columns : [ //MODELCODE,PARENTCODE,MODELNAME,REMARK,SEQ,URL,FRAME,IMAGES,STATE
				{headerText : "编号", dataField : "MODELCODE", headerAlign : "center", width : "120" }, 
				{headerText : "名称", dataField : "MODELNAME", headerAlign : "center", width : "120", dataAlign : "center", width : "100"}, 
				{headerText : "序号", dataField : "SEQ", headerAlign : "left", width : "80", dataAlign : "center", width : "100", editable:caneditable}, 
				{headerText : "状态", dataField : "STATE", headerAlign : "left", width : "80", dataAlign : "center", width : "100", editable:caneditable},  
				{headerText : "备注", dataField : "REMARK", headerAlign : "center", dataAlign : "center", width : "100"}
				 
			],
			keyfield : "MODELCODE",
			pkeyfield : "PARENTCODE",
			titlefield : "MODELNAME",
			iconfield : "",
			//sql : sql,
			store:softExtendstore,
			subtype : 'treegrid'
		};
		function itemClickEvent(id, index, data) {
			console.log(
					id + ", " + index + ", "
							+ TreeGrid.json2str(data));
		}
		$("#softextendInfo").empty();
		var treeGrid = new TreeGrid(config);
		treeGrid.show();
		//编辑全部时,使输入框填充td
    if(caneditable){
			$('#softextendInfo td input[type="text"]').width("100%");
 		}
	};
 
	function buildSofConfig(caneditable){

		var softItemStoreSql ="SELECT actcode, actname, parentcode, ordseq, acttype, provider, url, actfun, refmodel, getright, dockplace, remark, iconclass FROM metasoft_action where provider='"+objcode+"'   order by acttype";
 		softItemStore= new AI.JsonStore({
			sql:softItemStoreSql,
			pageSize:-1,
			key:'ACTCODE',
			table:'metasoft_action',
			dataSource:'METADB'
  		});
    var config={
			store:softItemStore,
			pageSize:15,
			containerId:'metasoftaction',
			nowrap:true,
			showcheck:true,
			bAutoWidth:false,  
			celldblclick:_rowdblClickFunc,
			columns:[
				{header: "配置编码", width:74,dataIndex: 'ACTCODE'},
				{header: "配置名称", width:74, dataIndex: 'ACTNAME',sortable: true},
				{header: "上级编码", width:74, dataIndex: 'PARENTCODE',editable:caneditable},
				{header: "方法", width: 50, dataIndex: 'ACTFUN', sortable: true,editable:caneditable,maxLength:50},
				{header: "URL", width:50,dataIndex: 'URL',editable:caneditable,maxLength:50},
				{header: "影响对象", width:74, dataIndex: 'REFMODEL',editable:caneditable},
				{header: "图标样式", width:74, dataIndex: 'ICONCLASS',editable:caneditable},
				{header: "触发方式", width:74,dataIndex: 'DOCKPLACE',editable:caneditable},
				{header: "权限控制", width:50, dataIndex: 'GETRIGHT',editable:caneditable,maxLength:50}			
			]
		};
		$("#metasoftaction").empty();
		var grid =new AI.Grid(config);
	};
	var _rowdblClickFunc = function(val,record){
			buildSoftFrameFormCfg('y');
	        ai.openFormDialog("修改软件配置",softFrameItems,callBack,softItemStore);
			return false;
		};

    buildObjBaseInfo();
	buildSoftExtendInfo();
    buildSofConfig();
   //判断当前操作是否为批量编辑
   var isBachUpdate = false;
   $("#editSoftProperty").click(function(){
   		isBachUpdate = true;
    	buildSoftExtendInfo(true);
   });
   $("#saveSoftProperty").click(function(){
   		isBachUpdate = false;
   		softExtendstore.commit();
   		buildSoftExtendInfo();
   		alert("保存成功");
   });
   $("#installSoftProperty").click(function(){
   		softaction.installSoft(objcode);
   });
   //编辑基本信息
   $("#editObjInfo").click(function(){
       // metasoft.registNewMetaObj({objtype:objtype,objid:objcode,storeAtMetaObj:'n'});
        metasoft.editMetaObjBaseInfo({objtype:objtype,objid:objcode,storeAtMetaObj:'n',aftSave:buildObjBaseInfo}); 
    });
   $("#edit-obj").click(function(){
   		buildSofConfig(true);
   });
   $("#save-obj").click(function(){
   		softItemStore.commit();
   		alert("保存成功!!");
   		buildSofConfig();
   });
   //编辑当前
   function buildSoftFrameFormCfg(isAdd){
	   	isCreate = true;
   		softFrameItems = [
			{type:'text',label:'配置编码',fieldName:'ACTCODE',notNull:'N',width:320,isReadOnly:isAdd},
			{type:'text',label:'配置名称',fieldName:'ACTNAME',width:320},
			{type:'text',label:'上级编码',fieldName:'PARENTCODE',width:320},
			{type:'text',label:'方法',fieldName:'ACTFUN',width:320},
			{type:'text',label:'URL',fieldName:'URL',width:320},
			{type:'checkbox',label:'影响对象',fieldName:'REFMODEL',storesql:"select objtype,objname from metaobjmodel where parentcode='META-OTHER' or parentcode in (select objcode from metaobjmodel where parentcode='META')",width:320}
			,{type:'text',label:'图标样式',fieldName:'ICONCLASS',width:320},
			{type:'checkbox',label:'触发方式',fieldName:'DOCKPLACE',storesql:"rightmenu,rightmenu|toolbar,toolbar|lv3_toolbar,lv3_toolbar",width:320},
			{type:'textarea',label:'权限控制',fieldName:'GETRIGHT',width:320}
		];
   }
   $("#edit-obj-now").click(function(){
	    isCreate=false;
	    buildSoftFrameFormCfg('y');
   		ai.openFormDialog("修改软件配置",softFrameItems,callBack,softItemStore);
   });
   $("#add-obj").click(function(){
	    isCreate=true;
	    var curRecord=softItemStore.curRecord;
	    buildSoftFrameFormCfg('n');
  		ai.openFormDialog("添加软件",softFrameItems,callBack,null);
  		$("#ACTTYPE").val("action");
  });
   var callBack =function(){
   	var actcode = $("#ACTCODE").val();
   	var parentcode = $("#PARENTCODE").val();
   	var actname = $("#ACTNAME").val();
	var actfun = $("#ACTFUN").val();
	var url = $("#URL").val();
   	var refmodel = "";
   	var strFun=document.getElementsByName("REFMODEL");
	for(var i=0;i<strFun.length;i++){
		if(strFun[i].checked){
			refmodel += strFun[i].value + ",";
		}
	}
	refmodel = refmodel.substring(0,refmodel.lastIndexOf(","));
   	var iconclass = $("#ICONCLASS").val();
	var dockplace = "";
	var strDoc=document.getElementsByName("DOCKPLACE");
	for(var i=0;i<strDoc.length;i++){
		if(strDoc[i].checked){
			dockplace += strDoc[i].value + ",";
		}
	}
	dockplace = dockplace.substring(0,dockplace.lastIndexOf(","));
	var getright = $("#GETRIGHT").val();	
	var rec = softItemStore.getNewRecord();
   	rec.set("ACTCODE",actcode);
   	rec.set("ACTNAME",actname);
   	rec.set("PARENTCODE",parentcode);
   	rec.set("ACTFUN",actfun);
   	rec.set("URL",url);
   	rec.set("REFMODEL",refmodel);
   	rec.set("ICONCLASS",iconclass);
   	rec.set("DOCKPLACE",dockplace);
   	rec.set("GETRIGHT",getright);
   	rec.set("PROVIDER",objcode);
   	//先校验上级编号是否是存在
   	if(parentcode){
   		var isParent = softItemStore.getRecordByKey(rec.get("PARENTCODE"));
   		if(isParent || parentcode==""){
   			
   		}else{
   			alert("父级编号不存在");
   			return false;
   		}
   	}
   	if(actcode){
   		if(isCreate){
   			softItemStore.add(rec);
   		}else{
   			softItemStore.curRecord.set("ACTNAME",actname);
   			softItemStore.curRecord.set("PARENTCODE",parentcode);
   			softItemStore.curRecord.set("ACTFUN",actfun);
   			softItemStore.curRecord.set("URL",url);
   			softItemStore.curRecord.set("REFMODEL",refmodel);
   			softItemStore.curRecord.set("ICONCLASS",iconclass);
   			softItemStore.curRecord.set("DOCKPLACE",dockplace);
   			softItemStore.curRecord.set("GETRIGHT",getright);
   		}
   	}else{
   		alert("请填写带\" * \"的必填项！");
		return false;
   	}
   	softItemStore.commit();
   	buildSofConfig();
   }
   });
</script>
</head>
<body class="">
	<div class="container-fluid">
		 
		<div class="row" id="taskInfo">
			<div class="col-sm-3" style="padding-left: 1px; padding-right: 1px">
				<h5> 软件基本信息<small id='tip'> </small> </h5>
				<section class="panel panel-info portlet-item" style="opacity: 1; z-index: 0;">
					<header class="panel-heading"> 详细信息 </header>
					<div class="panel-body "
						style="width: 100%; height: auto; padding: 0px" id="objbaseinfo">

					</div>
					<footer class="panel-footer" > <a href="#" id="editObjInfo" class="btn btn-danger  btn-xs " enabled="">  <i class="glyphicon glyphicon-user"></i>编辑</a> </footer>
				</section>
			</div>
			<div class="col-sm-9">

				<h5><span id="funaction">软件分项详细信息</span></h5>

				<section class="panel panel-info">
					<header class="panel-heading">
						<span class="hidden-sm"> &nbsp; </span> <span id="taskname" style="float: left"></span>
						<ul class="nav nav-tabs pull-right">
							 
							
							<li class="active"><a href="#tab1" data-toggle="tab"> <i class="fa fa-user text-muted"> </i> 功能列表 </a></li>
							<li ><a href="#tab2" data-toggle="tab"> <i class="fa fa-comments text-muted"> </i> Action列表 </a></li>
							<li class=""><a href="#tab3" data-toggle="tab"> <i class="fa fa-user text-muted"> </i> 其它配置信息 </a></li>
						</ul>

					</header>
					<div class="panel-body">
						<div class="tab-content" style="min-height:300px">
						 
							<div class="tab-pane  active" id="tab1">
									<button id="editSoftProperty" class="btn btn-danger  btn-xs " enabled="">  <i class="glyphicon glyphicon-user"></i>编辑</button>
									<button id="saveSoftProperty" class="btn btn-danger  btn-xs " enabled="">  <i class="glyphicon glyphicon-user"></i>保存</button>
									<button id="installSoftProperty" class="btn btn-danger  btn-xs " enabled="">  <i class="glyphicon glyphicon-user"></i>安装</button>
								<div class="panel-body" id="softextendInfo"></div>
							</div>
							<div class="tab-pane " id="tab2">
								<div id='toolbar'>工具栏：
									<a href="#" id="edit-obj" class="btn btn-xs btn-primary " > <i class="fa fa-minus-square"></i>批量编辑</a>
									<a href="#" id="edit-obj-now" class="btn btn-xs btn-primary " > <i class="fa fa-minus-square"></i>编辑当前</a>
									<a href="#" id="add-obj" class="btn btn-xs btn-primary " > <i class="fa fa-minus-square"></i>添加</a>
									<a href="#" id="save-obj" class="btn btn-xs btn-primary " >  <i class="glyphicon glyphicon-zoom-in"></i>保存</a>
								</div>
								<div id="metasoftaction"></div>
								
							</div>
							<div class="tab-pane" id="tab3">
								<div id='toolbar'></div>
								<div id="softconfig11"></div>
							</div>
						</div>
					</div>
				</section>
			</div>
		</div>
	</div>
	</div>
 
</body>
</html>